package com.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.domain.*;
import com.alibaba.fastjson.JSON;

import com.webservice.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/approver")
public class ApproverController {

    @Resource
    private UserWebservice userWebservice;

    @Resource
    private OrderWebservice orderWebservice;

    @Resource
    private EquipmentWebservice equipmentWebservice;

    @Resource
    private BiddingWebservice biddingWebservice;

    @Resource
    private ProcessWebservice processWebservice;

    @Resource
    private StatisticsWebService statisticsWebService;


    /**
     * 待审核维修单列表
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/approveOrder")
    public String approveOrder(Model model, HttpServletRequest request){

        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        Map<Maintenance_order,Maintenance_process> map = new HashMap<>();
        List<Maintenance_order> m_orders = new ArrayList<Maintenance_order>();
        List<Maintenance_order> list_order = new ArrayList<>();
        List<Maintenance_order> maintenance_orders = processWebservice.findTask(approver.getId());
        if(maintenance_orders!=null){
            for(Maintenance_order orders:maintenance_orders){
                if(orders.getOrder_state()==1||orders.getOrder_state()==13){
                    list_order.add(orders);
                   // Order_details order_details = orderWebservice.findOrderDetails(orders.getId());
                 //   List<Maintenance_process> maintenance_processes = order_details.getMaintenanceProcessList();
                  //  for(Maintenance_process mp:maintenance_processes){
                      //  if(mp.getTask_id()==1){
                          //  map.put(orders,mp);
                     //   }
               //     }
                }
            }
        }
model.addAttribute("orders",list_order);
      //  model.addAttribute("orders",map);
        return "approver/approveOrder";
    }

    /**
     * 待审核的竞单申请
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/approveBidding")
    public String approveBidding(Model model, HttpServletRequest request){

        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        Map<Maintenance_order,Maintenance_process> map = new HashMap<>();
        model.addAttribute("approver", approver);
        List<Maintenance_order> orderlist =new ArrayList<Maintenance_order>();
        List<Maintenance_order> maintenance_orders = processWebservice.findTask(approver.getId());
        List<User> users = userWebservice.findReviewerByDepartment();
          if (maintenance_orders!=null){
            for (Maintenance_order orders:maintenance_orders){
                if (orders.getOrder_state() == 2){
                    Order_details order_details = orderWebservice.findOrderDetails(orders.getId());
                    List<Maintenance_process> maintenance_processes = order_details.getMaintenanceProcessList();
                    for(Maintenance_process mp:maintenance_processes){
                        if(mp.getTask_id()==2){
                            map.put(orders,mp);
                        }
                    }
                    }
                }
            }
          model.addAttribute("reviewers", users);
        model.addAttribute("orders",map);
        return "approver/approveBidding";
    }

    /**
     * 待审核的竞单申请
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/approvePriceList")
    public String approvePriceList(Model model, HttpServletRequest request){

        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        List<Maintenance_order> maintenance_orders = processWebservice.findTask(approver.getId());
        Map<Maintenance_process, Maintenance_order> map = new HashMap<>();
        if (maintenance_orders!=null){
            for (Maintenance_order orderTask:maintenance_orders){
                if (orderTask.getOrder_state() == 6){
                    Maintenance_order maintenance_order = orderWebservice.findOne(orderTask.getId());
                    Order_details order_details = orderWebservice.findOrderDetails(orderTask.getId());
                    List<Maintenance_process> maintenance_processes = order_details.getMaintenanceProcessList();
                    for(Maintenance_process mps:maintenance_processes){
                        if(mps.getTask_id()==1) //设备保修时间
                            map.put(mps, maintenance_order);
                    }
                }
            }
        }
        model.addAttribute("maps", map);

        return "approver/approvePrice";
    }

    /**
     * 验收审核维修单列表
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/approveCompletion")
    public String approveCompletion(Model model, HttpServletRequest request){

       HttpSession session = request.getSession();
       User approver = (User) session.getAttribute("user");
       model.addAttribute("approver", approver);
       List<User> users = userWebservice.findReviewerByDepartment();

       List<Maintenance_order> maintenance_orders = processWebservice.findTask(approver.getId());
       Map<Maintenance_order, Maintenance_process> map = new HashMap<>();
        List<Maintenance_order> lists = new ArrayList<>();
        if(maintenance_orders!=null){
            for (Maintenance_order orders:maintenance_orders){
                if (orders.getOrder_state() == 6||orders.getOrder_state()==5){
                    Maintenance_order maintenance_order = orderWebservice.findOne(orders.getId());
                    lists.add(orders);
                }
            }
        }
        model.addAttribute("reviewers",users);
        model.addAttribute("maps",lists);

        return "approver/approveCompletion";
    }

    /**
     * 根据维修单id查询所有竞单
     * @param map
     * @return
     * @ResponseBody接收前端传递过来的json数据
     */
    @RequestMapping("/findAllByOrder")
    @ResponseBody
    public List<Bidding> findAllByOrder(@RequestBody Map<String,String> map){
        Integer order_id = Integer.valueOf(map.get("id"));
        List<Bidding> biddingList = biddingWebservice.findAllByOrder(order_id);
        return biddingList;
    }

    /**
     * 查找维修单
     * @param
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/findOrder")
    @ResponseBody
    public Maintenance_order findOrderById(@RequestBody Maintenance_order maintenance_order, Model model, HttpServletRequest request){

          maintenance_order = orderWebservice.findOne(maintenance_order.getId());
          return maintenance_order;
    }

    /**
     * 查找所有维修师傅
     * @return
     */
    @RequestMapping("/findMaintenancePerson")
    @ResponseBody
    public List<User> findMaintenancePerson(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        Integer order_id = Integer.valueOf(map.get("id"));
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //通过维修单id查找维修类型的id
        Maintenance_order maintenance_order = orderWebservice.findOne(order_id);
        List<User> userList = userWebservice.findAllMaintenance_Person(maintenance_order.getDepartment_id());
        List<User> userList1 = userWebservice.findAllMaintenance_Person(3);
        if (userList1 != null){
            userList.addAll(userList1);
        }
        return userList;
    }

    /**
     * 审核员选择开始竞单
     * @param map
     * @return bidreject
     */
    @RequestMapping("/approveOrderCompany")
    public String approveOrderCompany(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        Integer order_id = Integer.valueOf(map.get("orderId"));
        Float price = Float.parseFloat(map.get("price"));
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        return "redirect:/approver/approveOrder";
    }
    /**
     *
     * @param map
     * @return bidreject
     */
    @RequestMapping("/bidreject")
    public String bidreject(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        Integer order_id = Integer.valueOf(map.get("orderId"));
        String reason = map.get("reason").trim();
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        int i = processWebservice.choose_Refuse(order_id,reason,approver.getId());
        return "redirect:/approver/approveBidding";
    }

    /**
     *
     * @param map
     * @return
     */
    @RequestMapping("/approveReject")
    public String approveReject(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){

        Integer order_id = Integer.valueOf(map.get("orderId"));
        String reason = map.get("reason").trim();
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        int i = processWebservice.approveOrder_Refuse(order_id,reason,approver.getId());
        return "redirect:/approver/approveOrder";
    }

    /**
     * 审核员审核维修单并选择个人维修
     * @param map
     * @return
     */
    @RequestMapping("/approveOrderPerson")
    public String approveOrderPerson(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        Integer order_id = Integer.valueOf(map.get("orderId"));
        Integer personid = Integer.valueOf(map.get("personId"));
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
       //int i = processWebservice.approveOrder_Repair(order_id,personid,approver.getId());
//        System.out.println(i);
        return "redirect:/approver/approveOrder";
    }

    /**
     * 选定维修公司进行维修
     * @param map
     * @return
     */
    @RequestMapping("/approveChooseCompany")
    public String approveChooseCompany(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
//        System.out.println("&&&&&&&&&&&123456");
        int i = 10;
        Integer order_id = Integer.valueOf(map.get("orderId"));
//        System.out.println(order_id);
        String viewer_id =map.get("viewId");
//        System.out.println(viewer_id);
        Integer comId = Integer.valueOf(map.get("comId"));
//        System.out.println(comId);
//        System.out.println(approver.getId());
        if(viewer_id!="") {
            i = processWebservice.choose_Company(order_id, comId, viewer_id + ",", approver.getId());
        }else{
             i = processWebservice.choose_Company(order_id, comId, "", approver.getId());
        }
//        System.out.println("0000000---1111"+i);
        return "redirect:/approver/approveBidding";
    }

    /*查看该部门下所有的人员信息*/
    @RequestMapping("/persioninfo")
    public String persioninfomation(Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        int number1=0,number2=0,number3=0;
        List<User> users = new ArrayList<User>();
        User user1 = new User();
        List<User> useres = userWebservice.findUserByDepartment_id(approver.getDepartment_id());
        if(useres!=null) {
            for (User user : useres) {
                 user1=userWebservice.findById(user.getId());
                    if(user.getRole_id()>1) {
                        users.add(user1);
                        if(user.getRole_id()==2)
                            number1++;
                        if(user.getRole_id()==3)
                            number2++;
                        if(user.getRole_id()==4)
                            number3++;
                    }
            }
            model.addAttribute("users",users);
        }
        model.addAttribute("number1",number1);
        model.addAttribute("number2",number2);
        model.addAttribute("number3",number3);
        return "/approver/persioninfo";
    }

    /**
     * 所有设备信息列表
     * @param model
     * @param request
     * @return
     */

    @RequestMapping("/allEquipment")  /*如何通过部门id显示所有设备信息*/
    public String equipmentinfo(Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        Map<Maintenance_order,Equipment> map = new HashMap<>();
        Integer num = 1;
        model.addAttribute("approver", approver);
        //通过维修单id查找维修类型的id
        List<Equipment> equipmentList = new ArrayList<Equipment>();
        equipmentList = equipmentWebservice.findAllEquipment();
        model.addAttribute("e_list",equipmentList);
        model.addAttribute("num",num);
        return "/approver/allEquipment";
    }

    /**
     * 所有信息列表页面
     * @param time
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/allOrderinfo")
    public String allOrderinfomation(String time,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        float sum = 0;
        int num = 0;
            if (time != null) {
                List<Maintenance_order> maintenance_orders = new ArrayList<Maintenance_order>();
                maintenance_orders = orderWebservice.findAll(time,approver.getDepartment_id());
                if (maintenance_orders!=null) {
                    for (Maintenance_order orders : maintenance_orders) {
                        sum = sum + orders.getFinal_price();
                    }
                    model.addAttribute("number", maintenance_orders.size());
                }else{
                    model.addAttribute("number", 0);
                }

                model.addAttribute("price", sum);
                model.addAttribute("orderlist", maintenance_orders);
            } else {
                List<Maintenance_order> maintenance_orders = new ArrayList<Maintenance_order>();
                Date date = new Date(System.currentTimeMillis());
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
                time = sdf.format(date);
                maintenance_orders = orderWebservice.findAll(time,approver.getDepartment_id());
                if (maintenance_orders!=null) {
                    for (Maintenance_order orders : maintenance_orders) {
                        sum = sum + orders.getFinal_price();
                    }
                    model.addAttribute("number", maintenance_orders.size());
                }else{
                    model.addAttribute("number", 0);
                }
                model.addAttribute("price", sum);
                model.addAttribute("orderlist", maintenance_orders);
            }
        model.addAttribute("time",time);
        return "/approver/allOrderinfo";
    }

    /**
     * 账号审核
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/registeradmin")
    public String registeradmininfo(Model model, HttpServletRequest request){

        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        List<User> userList = userWebservice.findUserByState(1);
        List<User> users = new ArrayList<User>();
        if (userList != null){
            for (User user:userList){
                if (user.getRole_id() != -1 && user.getRole_id()!=-2 && user.getRole_id()!=3) {
                    users.add(user);

                }
                }
            }
        model.addAttribute("users",users);

        return "/approver/registeradmin";
    }
    /*公司注册账号审核*/
    @RequestMapping("/registercompany")
    public String registercompanyinfo(Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        List<User> userList = userWebservice.findUserByState(1);
        List<User> users = new ArrayList<User>();
        if (userList != null){
            for (User user:userList){
                if (user.getRole_id() == -1 ||user.getRole_id()==-2){ //-1为维修公司角色id
                    user = userWebservice.findById(user.getId());
                    users.add(user);
                }
            }
        }
        model.addAttribute("users",users);
        return "/approver/registercompany";
    }

    /*审批员注册账号审核*/
    @RequestMapping("/registerView")
    public String registerView(Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        List<User> userList = userWebservice.findUserByState(1);
        List<User> users = new ArrayList<User>();
        if (userList != null){
            for (User user:userList){
                if (user.getRole_id() == 4 ){ //-1为维修公司角色id
                    users.add(user);
                }
            }
        }
        model.addAttribute("users", users);
        return "/approver/registerView";
    }

    @RequestMapping("/registerperson")
    public String registerpersoninfo(Model model, HttpServletRequest request){

        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        List<User> userList = userWebservice.findUserByState(1);
        List<User> users = new ArrayList<User>();
        if (userList != null){
            for (User user:userList){
                if (user.getRole_id() == -2 ){ //-2为维修工人角色id
                    users.add(user);
                }
            }
        }

        model.addAttribute("users", users);
        return "/approver/registerperson";
    }

    @RequestMapping("/reigsterInsidedepartment")
    public String registerInsidedepartmentinfo(Model model, HttpServletRequest request){

        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        List<User> userList = userWebservice.findUserByState(1);
        List<User> users = new ArrayList<User>();
        if (userList != null){
            for (User user:userList){
                if (user.getRole_id() == -3 ){ //-3为维修部门id
                    users.add(user);
                }
            }
        }
        model.addAttribute("users", users);
        return "/approver/reigsterInsidedepartment";
    }

    /**
     * 待审核的竞单申请
     * @param
     * @param
     * @return
     */
   @RequestMapping("/findallOrder")
    @ResponseBody
    public List<Maintenance_order> findallOrder(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approve = (User) session.getAttribute("user");
        String time =map.get("time").toString();
//        System.out.println(time);
        List<Maintenance_order> maintenance_orders = orderWebservice.findAll(time,approve.getDepartment_id());
        //System.out.println(time + maintenance_orders);
        return  maintenance_orders;
    }
    /**
     * 查找所有审批员,用于审批员的指定
     * @return
     */
    @RequestMapping("/findViewer")
    @ResponseBody
    public List<User> findViewer(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        Integer order_id = Integer.valueOf(map.get("id"));
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //通过维修单id查找维修类型的id
//        List<User> users = new ArrayList<User>();
        List<User> userList = userWebservice.findReviewerByDepartment();
        //System.out.println(userList);
//        for(User user:userList){
//            if(user.getRole_id()==4){
//                users.add(user);
//            }
//        }
        return userList;
    }

    /**
     * *验收拒绝
     * @param map
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/completeReject")
    public String completeReject(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){

        HttpSession session = request.getSession();
        Integer order_id = Integer.valueOf(map.get("orderId"));
        String reason = map.get("reason").trim();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
       // int i = processWebservice.approver_Refuse(order_id,reason);
        return "redirect:/approver/approveCompletion";
    }

    /**
     * *注册审核判断
     * @return
     */
    @RequestMapping("/registerChoice")
    public String registerChoice(Integer user_id,Integer choice){
        //System.out.println(user_id);
        userWebservice.updateAccount_state(user_id,2);
        if(choice == 1) {
            return "redirect:/approver/registeradmin";
        }else{
            return "redirect:/approver/registercompany";
        }
    }

    /**
     * *注册审核判断
     * @return
     */
    @RequestMapping("/registereject")
    public String registereject(Integer user_id,Integer choice){
        userWebservice.delUser(user_id);
        if(choice == 1) {
            return "redirect:/approver/registeradmin";
        }else{
            return "redirect:/admin/outsideReg";
        }
    }

    /**
     * *根据维修单来找相关所有的维修单详情
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/maintence_orderdetail")
    public String maintence_orderdetail(Integer equipment_id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        int num = 1;
        String equ_name = null;
        List<Maintenance_order> maintenance_orders = new ArrayList<Maintenance_order>();
        maintenance_orders = orderWebservice.findOrderByEquipment(equipment_id);
        Equipment equipment = equipmentWebservice.findById(equipment_id);
        model.addAttribute("orders",maintenance_orders);
        model.addAttribute("name",equipment);
        return "/approver/maintence_orderdetail";
    }

    /**
     * 通过设备id查找设备的详情信息
     * @param
     * @param
     * @return
     */
    @RequestMapping("/findequById")
    @ResponseBody
    public Equipment findequById(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");

//        String path = "D:/mmms-assets/";
//        String file = approver.getIcon();
//        //1.jpg,2.jpg,
//        String[] strings = file.split(",");
//        if (strings!=null){
//            for (String str:strings){
//                if (str!=null && !str.equals("")){
//                    str
//                }
//            }
//        }
        List<String> strings1 = new ArrayList<>();

        model.addAttribute("approver", approver);
        Integer equ_id  = Integer.valueOf(map.get("id"));
        Equipment equipment = equipmentWebservice.findById(equ_id);
        return  equipment;
    }

    /**
     * 验收清单页面
     * @param
     * @return
     */
    @RequestMapping("/completeList")
    public String completeList(Integer order_id,Model model, HttpServletRequest request){
        //System.out.println("oooooo");
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        List<Expense_details> list = new ArrayList<>();
        Order_details order_details= orderWebservice.findOrderDetails(order_id);
        Maintenance_order m_ord = orderWebservice.findOne(order_id);
        if(order_details!=null){
            list = order_details.getExpense_detailsList();}
        model.addAttribute("completelist",list);
        model.addAttribute("orders",m_ord);
        return "/approver/completeList";
    }
    /**
     * *查询注册人员的详情信息
     * @param id
     * 通过注册人员id信息来
     * @param request
     * @return
     */
    @RequestMapping("/registerdetails")
    public String registerdetails(Integer id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        User users = userWebservice.findById(id);
        model.addAttribute("users",users);
        return "/approver/registerdetails";
    }

    /**
     * *打印所有维修单的流程信息
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/print_process")
    public String print_process(Integer order_id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        Maintenance_order order = orderWebservice.findOne(order_id);
        Order_details order_details = orderWebservice.findOrderDetails(order_id);
        List<Maintenance_process> mp = order_details.getMaintenanceProcessList();
        model.addAttribute("list",mp);
        model.addAttribute("orders",order);
        return "/approver/print_process";
    }

    /**
     * 通过设备id查找设备的详情信息
     * @param
     * @param
     * @return
     */
    @RequestMapping("/finduser")
    @ResponseBody
    public User finduser(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        Integer id = Integer.valueOf(map.get("id"));
        User users = userWebservice.findById(id);
        return  users;
    }
    /**
     * 公司注册审核图片显示页面
     * @param
     * @param
     * @return
     */
    @RequestMapping("/comRegisterDetail")
    public String comRegisterDetail(Integer id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver",approver);
        User users = userWebservice.findById(id);
        String photoes = users.getQualification_image();
        String phonto_one=users.getBusiness_license();
        List<String> map = new ArrayList<>();
        if(photoes!=null){
            String[] strings = photoes.split(",");
            if (strings!=null){
                for (String str:strings){
                    if (str!=null && !str.equals("")){
                        map.add(str);
                    }
                }
            }
            model.addAttribute("photoes",map);
        }
        model.addAttribute("photo",phonto_one);
        return  "/approver/comRegisterDetail";
    }
    /**
     * 注册审核的图片显示问题
     * @param
     * @param
     * @return
     */
    @RequestMapping("/registerIco")
    public String registerIco(Integer id,Model model, HttpServletRequest request) {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        User users = userWebservice.findById(id);
        model.addAttribute("photo",users.getIcon());
        model.addAttribute("name", users.getName());
        return "/approver/registerIco";
    }
    @RequestMapping("/approveSelect")
    public String approveSelect(Integer order_id,Integer company_id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver",approver);
        List<Maintenance_process> second_reviewerAdvice = new ArrayList<>();
        List<Maintenance_process> second_reviewerAcceptAdvice = new ArrayList<>();
        String a="";
        String b="";
        String c="";
        String d="";
        String e="";
        String f = "";
        List<Maintenance_process> maintenance_processList = orderWebservice.findProcess(order_id);
        for (Maintenance_process maintenance_process:maintenance_processList) {
            if (maintenance_processList != null) {
                if (maintenance_process.getTask_id() == 4){
                    User user = userWebservice.findById(maintenance_process.getTransactor_id());
                    if (user.getRole_id()  == 4){
                        second_reviewerAdvice.add(maintenance_process);
                    }
                }
                if (maintenance_process.getTask_id() == 8) {
                    User user = userWebservice.findById(maintenance_process.getTransactor_id());
                    if (user.getRole_id() == 4) {
                        second_reviewerAcceptAdvice.add(maintenance_process);
                    }
                }
            }
        }
        model.addAttribute("review_advice",second_reviewerAdvice);
        model.addAttribute("review_accpet",second_reviewerAcceptAdvice);
        Maintenance_order maintenance_order = orderWebservice.findOne(order_id);
        List<User> userList = userWebservice.findAllMaintenance_Person(maintenance_order.getDepartment_id());
        List<User> userList2 = userWebservice.findAllMaintenance_Person(3);
       // List<User> users = userWebservice.findAllMaintenance_Person(3);
        String photoes = maintenance_order.getProblem_image();
        List<String> map = new ArrayList<>();
        List<Maintenance_request> requests = new ArrayList<>();
        requests = orderWebservice.findAllRequest(order_id);
        String videos = maintenance_order.getProblem_video();
        List<String> problem_video = new ArrayList<>();
        if(maintenance_order.getOrder_state()==13) {
            Bidding bid = biddingWebservice.findBiddingByCompany(order_id, company_id);
            List<Expense_details> lists  = new ArrayList<>();
            JSONArray arr = JSONObject.parseArray(bid.getExpenseDetailsList());
            for(Object ex:arr){
                JSONObject job = (JSONObject)ex;
                //System.out.println("&*****"+job.get("consumable_name"));
                String name = job.get("consumable_name").toString();
                float num = Float.parseFloat(job.get("consumable_num").toString());
                float price = Float.parseFloat(job.get("consumable_price").toString());
                Expense_details exs = new Expense_details();
                exs.setConsumable_price(price);
                exs.setConsumable_num(num);
                exs.setConsumable_name(name);
                lists.add(exs);
            }
            model.addAttribute("list_e", lists);
            model.addAttribute("bid", bid);
        }
        List<User> user_review = userWebservice.findUserByState(2);
        List<User> users_t = new ArrayList<User>();
        if (user_review!=null){
            for(User s : user_review){
                if(s.getRole_id()==4){
                    users_t.add(s);
                }
            }
            model.addAttribute("user_review",users_t);
        }
        if(photoes!=null){
            String[] strings = photoes.split(",");
            if (strings!=null){
                for (String str:strings){
                    if (str!=null && !str.equals("")){
                        map.add(str);
                    }
                }
            }
            model.addAttribute("photoes",map);
        }
        if(videos!=null){
            String[] strs = videos.split(",");
            if(strs!=null){
                for (String str:strs){
                    if (str!=null && !str.equals("")){
                        problem_video.add(str);
                    }
                }
            }
            model.addAttribute("video",problem_video);
        }

        if ((userList2!=null)&&userList==null){
            model.addAttribute("users",userList2);
        }else if((userList!=null)&&userList2==null){
            model.addAttribute("users",userList);
        }else if(userList!=null&&userList2!=null){
            model.addAttribute("users",userList);
        }else{
            userList2.addAll(userList);
            model.addAttribute("users",userList2);
        }
        if(requests!=null) {
            for (Maintenance_request request1 : requests) {
                if (request1.getRole_id() == 2) {
                    a = request1.getMaintenance_request();//这是设备管理员的要求
                }
                if (request1.getRole_id() == 3) {
                    if(request1.getUser_name().equals(maintenance_order.getEquipment_admin_name())){
                        f=request1.getMaintenance_request();
                    }else{
                        b = request1.getMaintenance_request();
                    }
                }
                if (request1.getRole_id() == 4) {
                    c = request1.getMaintenance_request();
                }
                }
        }
        model.addAttribute("a",a);
        model.addAttribute("b",b);
        model.addAttribute("c",c);
        model.addAttribute("f",f);
        model.addAttribute("order",maintenance_order);
        model.addAttribute("request",requests);

        return  "/approver/approveSelect";
    }
    //维修单指派
    @RequestMapping("/selectPeople")
    public String selectPeople(@RequestBody Map<String,String> map,Model model, HttpServletRequest request)
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approve", approver);
        //System.out.println("*****YESOK*****");
        //System.out.println(map.get("people"));
        int i = 0;
        if(map.get("price")!=null){
             i = processWebservice.approveOrder_Repair(Integer.valueOf(map.get("id")),Integer.valueOf(map.get("people")),
                    approver.getId(),map.get("state"),Float.valueOf(map.get("price")));
        }else {
            i = processWebservice.approveOrder_Repair(Integer.valueOf(map.get("id")), Integer.valueOf(map.get("people")),
                    approver.getId(), map.get("state"), (float)0.00);
        }
        //System.out.println(i);
        return "";
    }

    //审核员报修驳回
    @RequestMapping("/orderback")
    @ResponseBody
    public int orderback(@RequestBody Map<String,String> map,Model model, HttpServletRequest request)
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approve", approver);
        //System.out.println("******");
        //System.out.println(map.get("id"));
        //System.out.println(map.get("text"));
        int i = processWebservice.approveOrder_Refuse(Integer.valueOf(map.get("id")),map.get("text"),approver.getId());
        //System.out.println(i);
        return i;
    }
    /**
     *
     * @param model
     * @param request
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping("/publicRepair")
    public String publicRepair( Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);

        return "/approver/publicRepair";
    }
    //公共报修操作
    @RequestMapping("/repair")
    @ResponseBody
    public int repair(String name, String localtion,String problem_words, String time,String requests,MultipartFile[] photos,MultipartFile[] videos, Model model, HttpServletRequest request) throws IOException {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //图片上传
        String str = "";
        //System.out.println("0*******0");
        String path = "D:/mmms-assets/";
        for (MultipartFile pic : photos) {
            if (!pic.isEmpty()) {
                String originalFileName = pic.getOriginalFilename();
                // 新的图片名称
                String newFileName = UUID.randomUUID() + originalFileName.substring(originalFileName.lastIndexOf("."));
                // 新的图片
                File newFile = new File(path + newFileName);
                // 将内存中的数据写入磁盘
                pic.transferTo(newFile);
                //创建文件名用于上传
                str = str + newFileName + ",";
            }
        }
        //视频上传
        String str2="";
        for (MultipartFile vio : videos) {
            if (!vio.isEmpty()) {

                String originalFileName = vio.getOriginalFilename();
                // 新的图片名称
                String newFileName2 = UUID.randomUUID() + originalFileName.substring(originalFileName.lastIndexOf("."));
                // 新的图片
                File newFile = new File(path + newFileName2);
                // 将内存中的数据写入磁盘
                vio.transferTo(newFile);

                str2 = newFileName2;
            }
        }
        //System.out.println("11111222");
        Maintenance_order maintenance_order = new Maintenance_order();
        maintenance_order.setEquipment_id(6);
        maintenance_order.setOrder_name(name);
        maintenance_order.setMaintenance_location(localtion);
        maintenance_order.setProblem_image(str);
        maintenance_order.setProblem_word(problem_words);
        maintenance_order.setProblem_video(str2);
        maintenance_order.setDepartment_id(1);
        maintenance_order.setOrderPeriodOfValidity(Integer.valueOf(time));
        int i = processWebservice.start(approver,maintenance_order,1,requests);
        //System.out.println("*******"+i+"*******");
        return i;
    }
    //在办维修单列表
    @RequestMapping("/approveOrdering")
    public String ordering( Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        Map<Maintenance_order,Integer> map = new HashMap<>();
        List<Maintenance_order> ordersList = orderWebservice.findOrderByUser(approver.getId());
        int sum=0;
        if(ordersList!=null) {
            for (Maintenance_order maintenance_order : ordersList) {
                Maintenance_process mp = processWebservice.lastTaskName(maintenance_order.getId());
                if (maintenance_order.getOrder_state() != 10 && maintenance_order.getOrder_state() != 11)
                    map.put(maintenance_order, mp.getTransactor_id());
                    sum++;
            }
        }
        model.addAttribute("map",map);
        model.addAttribute("sum",sum);
        return "/approver/approveOrdering";
    }
    //审核员提交给审批员
    @RequestMapping("/sub_review")
    @ResponseBody
    public String sub_review(@RequestBody Map<String,String> map,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //System.out.println("******");
        int i = processWebservice.maintenance_review(Integer.valueOf(map.get("id")),approver.getId(),map.get("people"),map.get("state"),Float.valueOf(map.get("price")));
        //System.out.println(i);
        //System.out.println("******");
        return "";
    }

    //审核员验收申请
    @RequestMapping("/review_accpet")
    public String review_accpet(Integer id,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        String a="";
        String b="";
        String c="";
        List<Maintenance_request> requests = new ArrayList<>();
        requests = orderWebservice.findAllRequest(id);
        Maintenance_order maintenance_order = orderWebservice.findOne(id);
        model.addAttribute("order",maintenance_order);
        String photoes = maintenance_order.getProblem_image();
        List<User> user_review = userWebservice.findUserByState(2);
        List<User> users_t = new ArrayList<User>();
        List<Expense_details> expense_detailsList = new ArrayList<>();
        expense_detailsList = orderWebservice.findxpenseDetailsByOrder(id);
        model.addAttribute("expense_details", expense_detailsList);

        List<String> sou_video = new ArrayList<>();
        String video = maintenance_order.getSolution_video();
        List<Maintenance_process> first_reviewerAcceptAdvice = new ArrayList<>();
        List<Maintenance_process> maintenance_processList = orderWebservice.findProcess(id);
        if (maintenance_processList!=null){
            for (Maintenance_process maintenance_process:maintenance_processList){
                if (maintenance_process.getTask_id() == 8){
                    first_reviewerAcceptAdvice.add(maintenance_process);
                }
            }
        }
        model.addAttribute("first_reviewerAcceptAdvice", first_reviewerAcceptAdvice);
        for(User s : user_review){
            if(s.getRole_id()==4){
                users_t.add(s);
            }
        }
        model.addAttribute("user_review",users_t);
        List<String> map = new ArrayList<>();
        //System.out.println(photoes);
        if(photoes!=null){
            String[] strings = photoes.split(",");
            for (String str:strings){
                if (str!=null && !str.equals("")){
                    map.add(str);
                }
            }
            model.addAttribute("photoes",map);
        }
        if(requests!=null) {
            for (Maintenance_request request1 : requests) {
                if (request1.getRole_id() == 2) {
                    a = request1.getMaintenance_request();//这是设备管理员的要求
                    //System.out.println(a);
                }
                if (request1.getRole_id() == 3) {
                    if(request1.getUser_name().equals(maintenance_order.getEquipment_admin_name())){
                        c=request1.getMaintenance_request();
                    }else {
                        b = request1.getMaintenance_request();
                    }
                    //System.out.println(b);
                }
            }
        }
        if(video!=null){
            String[] strs = video.split(",");
            if(strs!=null){
                for (String str:strs){
                    if (str!=null && !str.equals("")){
                        sou_video.add(str);
                    }
                }

            }
            model.addAttribute("video",sou_video);
        }

        model.addAttribute("a",a);
        model.addAttribute("b",b);
        model.addAttribute("c",c);
        return "/approver/review_accpet";
    }
    //审核员验收申请通过
    @RequestMapping("/approve_pass")
    public int approve_pass(@RequestBody Map<String,String> map,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //System.out.println("验收审核"+map.get("review"));
        //注意这里的审批员可以为空
        int i = processWebservice.approver_Pass(Integer.valueOf(map.get("id")),map.get("review"),approver.getId());
        //System.out.println(i);
        return i;
    }
    //审核员验收拒绝通过
    @RequestMapping("/approve_no")
    public int approve_no(@RequestBody Map<String,String> map,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //注意这里的审批员可以为空
        int i = processWebservice.approver_Refuse(Integer.valueOf(map.get("id")),map.get("reason"),approver.getId());
        //System.out.println(i);
        return i;
    }
    //审核员发布竞单
    @RequestMapping("/bidingOrder")
    public String bidingOrder(@RequestBody Map<String,String> map,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //注意这里的审批员可以为空
        int i = 0;
        String people="";
        if(map.get("people")!=null){
            people = map.get("people");
        }
        if(map.get("price")==null){
            i = processWebservice.approveOrder_Bid(Integer.valueOf(map.get("id")), approver.getId(),Integer.valueOf(map.get("day")), map.get("state"),(float)0.00,people);
        }
        else {
            i = processWebservice.approveOrder_Bid(Integer.valueOf(map.get("id")), approver.getId(),Integer.valueOf(map.get("day")), map.get("state"),Float.valueOf(map.get("price")),people);
        }
        //System.out.println(i);
        return "";
    }
    //审核员将竞单提交给审批员
    @RequestMapping("/bid_reviewer")
    public String bid_reviewer(@RequestBody Map<String,String> map,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //注意这里的审批员可以为空
      //  int i = processWebservice.approveOrder_Bid(Integer.valueOf(id), approver.getId());
        int i = processWebservice.approver_review(Integer.valueOf(map.get("id")),approver.getId(),map.get("x")+",");
        //System.out.println(i);
        return "";
    }
    //审核员确认可以竞单道指派
    @RequestMapping("/affirm_approve")
    public String affirm_approve(@RequestBody Map<String,String> map,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //注意这里的审批员可以为空

        int i = processWebservice.makeSureUnit(Integer.valueOf(map.get("id")),approver.getId());
        //System.out.println(i);
        return "redirect:/approver/approveOrder";
    }
    //审核员的操作撤回
    @RequestMapping("/operate_back")
    public String operate_back(Integer id,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //注意这里的审批员可以为空
        int i = 6;
        Maintenance_order maintenance_order = orderWebservice.findOne(id);
        if(maintenance_order.getOrder_state()==14){
            i = processWebservice.approver_returnUnit(id,approver.getId());
        }else if(maintenance_order.getOrder_state()==4){
            i = processWebservice.approver_returnTask(id,approver.getId(),1);
        }else if(maintenance_order.getOrder_state()==7){
             i = processWebservice.approver_returnTask(id,approver.getId(),2);
        }else{
             i = processWebservice.approver_returnTask(id,approver.getId(),3);
        }
        //System.out.println(i);
        return "redirect:/approver/approveOrdering";
    }

    //审核员的对营房报修单打印
    @RequestMapping("/barracks")
    public String barracks(Integer id,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        String a = "";
        String b = "";
        String c = "";
        Maintenance_order maintenance_order = orderWebservice.findOne(id);
        model.addAttribute("order",maintenance_order);
        List<Maintenance_request> list = new ArrayList<>();
        list = orderWebservice.findAllRequest(id);
        if(list!=null){
            for(Maintenance_request list1:list){
                if(list1.getRole_id()==4){
                    a = list1.getUser_name();
                }
            }

        }
        model.addAttribute("a",a);
        return "/approver/barracks";
    }
    //c重新开始竞单
    @RequestMapping("/rebid")
    public String rebid(@RequestBody Map<String,String> map,Model model, HttpServletRequest request,HttpServletResponse response)throws IOException
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        //注意这里的审批员可以为空
        int i = processWebservice.approver_turnBid(Integer.valueOf(map.get("id")),approver.getId());
        //System.out.println(i);
        return "redirect:/approver/approveOrder";
    }

    @RequestMapping("/adminCompletion")
    public int adminCompletion(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        int i = processWebservice.equipment_admin_Pass(Integer.valueOf(map.get("id")));
        return i;
    }

    @RequestMapping("/unpass")
    public int unpass(@RequestBody Map<String,String> map,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        int i = processWebservice.equipment_admin_Refuse(Integer.valueOf(map.get("id")),map.get("reason"));
        return i;
    }
    @RequestMapping("/picture_Equipment")
    public String picture_Equipment(String str,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver",approver);
        List<String> map = new ArrayList<>();
        if(str!=null){
            String[] strings = str.split(",");
            if (strings!=null){
                for (String str1:strings){
                    if (str!=null && !str1.equals("")){
                        map.add(str);
                    }
                }
            }
            model.addAttribute("photoes",map);
        }else{
            model.addAttribute("photoes","");
        }
        return "/approver/picture_Equipment";
    }

    @RequestMapping("/bidOrder")
    public String bidOrder(Integer id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        List<Bidding> biddingList = biddingWebservice.findAllByOrder(id);
        Maintenance_order list = orderWebservice.findOne(id);
        model.addAttribute("list",list);
        model.addAttribute("bid",biddingList);
        return "/approver/bidOrder";
    }

    @RequestMapping("/newBid")
    public String newBid(Integer id,Integer com_id,Model model, HttpServletRequest request){
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approver", approver);
        List<Expense_details> expense_details = new ArrayList<Expense_details>();
        Bidding bid = biddingWebservice.findBiddingByCompany(id,com_id);
        Maintenance_order maintenance_order = orderWebservice.findOne(id);
        model.addAttribute("bid",bid);
        expense_details = JSON.parseArray(bid.getExpenseDetailsList(), Expense_details.class);
       System.out.println("维修清单"+expense_details);
        model.addAttribute("expense",expense_details);
        List<User> users_t = new ArrayList<User>();
        List<User> user_review = userWebservice.findUserByState(2);
        if (user_review!=null){
            for(User s : user_review){
                if(s.getRole_id()==4){
                    users_t.add(s);
                }
            }
            model.addAttribute("user_review",users_t);
        }
        model.addAttribute("order",maintenance_order);
        return "approver/newBid";
    }

    @RequestMapping("/equipmentstatis")
    public String equipmentstatis(String times,HttpServletRequest request, Model model) {
        HttpSession session = request.getSession();
        User admin = (User) session.getAttribute("user");
        model.addAttribute("admin", admin);
        Date time = new Date();
        int d1=0,d2=0,d3=0;//n完成m异常b正在进行
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String date = formatter.format(time);
        String year = date.substring(0,4);
        if(times!=null){
            year = times;
        }
        List<Map<String, Object>> lm = new ArrayList<>();
        List<Integer> lm2 = new ArrayList<>();
        List<Integer> lm3 = new ArrayList<>();
        List<Integer> lm4 = new ArrayList<>();
        int dates = Integer.parseInt(year);
        Map<String, Object> map = new HashMap<>();
        List<Integer> dt = new ArrayList<>();
        for(int i = dates-5;i<=dates;i++){
            map = JSON.parseObject(statisticsWebService.maintenancePriceAndTimes(String.valueOf(i)));
            //营房
            d1 = statisticsWebService.maintenanceTimesOfEquipmentYear(3,String.valueOf(i));
            //装备
            d2 = statisticsWebService.maintenanceTimesOfEquipYear(String.valueOf(i));
            //公共
            d3 = statisticsWebService.maintenanceTimesOfEquipmentYear(6,String.valueOf(i));
            lm.add(map);
            lm2.add(d1);
            lm3.add(d2);
            lm4.add(d3);
            dt.add(i);
        }
        model.addAttribute("house",lm2);
        model.addAttribute("equip",lm3);
        model.addAttribute("public1",lm4);
        model.addAttribute("dt",dt);
        model.addAttribute("list",lm);
        model.addAttribute("year",year);
        model.addAttribute("map",map);
        return "approver/equipmentstatis";
    }
    @RequestMapping("/orderSt")
    public String orderSt(String times,HttpServletRequest request, Model model) {
        HttpSession session = request.getSession();
        User admin = (User) session.getAttribute("user");
        model.addAttribute("admin", admin);
        Date time = new Date();
        int n =0,m = 0,b=0 ,id;//n完成m异常b正在进行
        float company=0.0f,people=0.0f;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String date = formatter.format(time);
        String year = date.substring(0,4);
        System.out.println(year);
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        List<Integer> list3 = new ArrayList<>();
        List<Float> list4 = new ArrayList<>();
        List<Float> list5 = new ArrayList<>();
        if(times!=null) {
            year = times;
        }
        for (int i = 1; i <= 12; i++) {
            List<Maintenance_order> list = new ArrayList<>();
            list = orderWebservice.findAllOrderByTime(year + "-" + i);
            if (list != null) {
                n = 0;
                m = 0;
                b = 0;
                company = 0;
                people = 0;
                for (Maintenance_order maintenance_order : list) {
                    if (maintenance_order.getUnit_id() != null) {
                        id = maintenance_order.getUnit_id();
                        User user = userWebservice.findById(id);
                        if (user != null) {
                            if (user.getRole_id() == -1) {
                                company = company + maintenance_order.getFinal_price();
                            }
                            if (user.getRole_id() == -2) {
                                people = people + maintenance_order.getFinal_price();
                            }
                        }
                    }
                    if (maintenance_order.getOrder_state() == 10) {
                        n++;
                    } else if (maintenance_order.getOrder_state() == 11) {
                        m++;
                    } else {
                        b++;
                    }
                }
                list1.add(n);
                list2.add(m);
                list3.add(b);
                list4.add(company);
                list5.add(people);
            } else {
                list1.add(0);
                list2.add(0);
                list3.add(0);
                list4.add(Float.valueOf("0"));
                list5.add(Float.valueOf("0"));
            }
        }
        model.addAttribute("list1", list1);
        model.addAttribute("list2", list2);
        model.addAttribute("list3", list3);
        model.addAttribute("list4", list4);
        model.addAttribute("list5", list5);

        List<Integer> list_1 = new ArrayList<>();
        List<Integer> list_2 = new ArrayList<>();
        List<Integer> list_3 = new ArrayList<>();
        for (int i = 1; i <= 12; i++) {
            List<Maintenance_order> maintenance_orders1 = orderWebservice.findAll(year + "-" + i, 1);//营房
            List<Maintenance_order> maintenance_orders2 = orderWebservice.findAll(year + "-" + i, 2);//装备
            List<Maintenance_order> maintenance_orders3 = orderWebservice.findAll(year + "-" + i, 3);//公共
            if (maintenance_orders1 != null) {
                list_1.add(maintenance_orders1.size());
            } else {
                list_1.add(0);
            }

            if (maintenance_orders2 != null) {
                list_2.add(maintenance_orders2.size());
            } else {
                list_2.add(0);
            }

            if (maintenance_orders3 != null) {
                list_3.add(maintenance_orders3.size());
            } else {
                list_3.add(0);
            }
        }
        model.addAttribute("list_1", list_1);
        model.addAttribute("list_2", list_2);
        model.addAttribute("list_3", list_3);

        model.addAttribute("year",year);
        return "approver/orderSt";
    }
    @RequestMapping("/human_satis")
    public String human_satis(String times,HttpServletRequest request, Model model) {
        HttpSession session = request.getSession();
        User admin = (User) session.getAttribute("user");
        model.addAttribute("admin", admin);
        Date time = new Date();
        int n =0,m = 0,b=0 ,id;//n完成m异常b正在进行
        float company=0.0f,people=0.0f;
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String date = formatter.format(time);
        String year = date.substring(0,4);
        List<User> userList = userWebservice.findUserByState(2);
        int q=0,w=0,e=0,r=0,t=0;
        if(times!=null){
            year = times;
        }
        Map<String, Object> map = new HashMap<>();

        Map<String, Object> map2 = new HashMap<>();
        int dates = Integer.parseInt(year);
        List<Integer> dt = new ArrayList<>();
        List<Map<String, Object>> lm1 = new ArrayList<>();

        for(int i = dates-5;i<=dates;i++){
            //公司
            map = JSON.parseObject(statisticsWebService.maintenancePriceOfMaintenanceUnitYear(String.valueOf(i)));
            lm1.add(map);
            //个人

            dt.add(i);
        }
        model.addAttribute("dt",dt);
        model.addAttribute("map",lm1);

        if (userList != null) {
            for(User user:userList){
                if(user.getRole_id()==-1){
                    q++;
                }else if(user.getRole_id()==-2){
                    w++;
                }else if(user.getRole_id()==2){
                    e++;
                }else if(user.getRole_id()==3){
                    r++;
                }else if(user.getRole_id()==4){
                    t++;
                }
            }
        }
        model.addAttribute("q",q);
        model.addAttribute("w",w);
        model.addAttribute("e",e);
        model.addAttribute("r",r);
        model.addAttribute("t",t);
        List<Float> list4 = new ArrayList<>();
        List<Float> list5 = new ArrayList<>();
        for(int i = 1;i<=12;i++) {
            List<Maintenance_order> list = new ArrayList<>();
            list = orderWebservice.findAllOrderByTime(year+"-"+i);
            if(list!=null) {
                n=0;
                m=0;
                b=0;
                company=0;
                people=0;
                for(Maintenance_order maintenance_order:list){
                    if(maintenance_order.getUnit_id()!=null) {
                        id = maintenance_order.getUnit_id();
                        User user = userWebservice.findById(id);
                        if (user != null) {
                            if (user.getRole_id() == -1) {
                                company=company+maintenance_order.getFinal_price();
                            }
                            if (user.getRole_id() == -2) {
                                people=people+maintenance_order.getFinal_price();
                            }
                        }
                    }
                    if(maintenance_order.getOrder_state()==10){
                        n++;
                    }else if(maintenance_order.getOrder_state()==11){
                        m++;
                    }else{
                        b++;
                    }
                }
                list4.add(company);
                list5.add(people);
            }else{
                list4.add(Float.valueOf("0"));
                list5.add(Float.valueOf("0"));
            }
        }
        model.addAttribute("list4",list4);
        model.addAttribute("list5",list5);
        model.addAttribute("year",year);
        return "approver/human_satis";
    }
    //预估报价
    @RequestMapping("/precompute")
    public int precompute(@RequestBody Map<String,String> map,Model model, HttpServletRequest request)
    {
        HttpSession session = request.getSession();
        User approver = (User) session.getAttribute("user");
        model.addAttribute("approve", approver);
        int i = 0;
        if(map.get("price")!=null){
            i = processWebservice.approveToGetEstimate(Integer.valueOf(map.get("id")),Integer.valueOf(map.get("people")),
                    approver.getId(),map.get("state"),Float.valueOf(map.get("price")));
        }else {
            i = processWebservice.approveToGetEstimate(Integer.valueOf(map.get("id")), Integer.valueOf(map.get("people")),
                    approver.getId(), map.get("state"), (float)0.00);
        }
        System.out.println(i);
        return i;
    }

}
